#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File    :main_controller.py
@Author  :keyin
@Time    :2021-02-19 10:50
"""
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QStackedLayout

from uis.main import Ui_main
from templates.basic_frame import MainPage
from controllers.CardCtl import CardCtl
from controllers.AppOutCtl import AppOutCtl



class MainController(MainPage, Ui_main):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        # 实例化子窗口
        self.card = CardCtl()
        self.app_out = AppOutCtl()

        # 设置堆叠布局
        self.qsl = QStackedLayout(self.frame_content)
        self.qsl.addWidget(self.card)
        self.qsl.addWidget(self.app_out)

        # 更改ui
        # self.change_ui()

        # 加载qss
        self.setStyleSheet(self.load_style('main.qss'))

        # 槽函数绑定
        self.bind_slot()

    def bind_slot(self):
        """
        绑定槽函数
        :return:
        """
        self.btn_card.clicked.connect(self.switch)
        self.btn_app.clicked.connect(self.switch)
        self.btn_check.clicked.connect(self.switch)

    def switch(self):
        """
        菜单栏切换
        :return:
        """
        sender = self.sender()

        index = {
            "btn_card": 0,
            "btn_app": 1,
            "btn_check": 2,
        }
        self.qsl.setCurrentIndex(index[sender.objectName()])

    def change_ui(self):
        # 无边框
        self.setWindowFlags(Qt.FramelessWindowHint)
        # 阴影
        eff_shadow = self.setShadow((0, 105, 157), r=1)
        self.btn_card.setGraphicsEffect(eff_shadow)
        # 圆角
        self.setCircle(self)
